# Maintainer: Alexey Pavlov <alexpux@gmail.com>

pkgname=tzcode
_ver=2015e
# use a pacman compatible version scheme
pkgver=${_ver/[a-z]/.${_ver//[0-9.]/}}
pkgrel=1
pkgdesc="Sources for time zone and daylight saving time data"
arch=('i686' 'x86_64')
url="http://www.iana.org/time-zones"
license=('GPL')
options=('!emptydirs')
groups=('base')
depends=('coreutils' 'gawk' 'sed')
source=(
        http://www.iana.org/time-zones/repository/releases/tzdata${_ver}.tar.gz
        http://www.iana.org/time-zones/repository/releases/${pkgname}${_ver}.tar.gz
        tzcode-makefile.patch
        tzcode-makefile-exe-extensions.patch
        tzcode-tzfile.patch
        tzcode-cygwin.patch
        tzcode-man1.patch
        tzcode-man3.patch
        tzcode-man8.patch)
sha1sums=('070179efcba7e6edaae1834c9ac1326d71373d65'
          '9502cd0d2508b74821287d3aa85a42f012e29a7a'
          'fdbd29f4b204c74f477cbba9777daa0e2dbed2e8'
          'ea2354956f2ae3c09527647486f7f501049d01da'
          '46feb526f958e4cc027e253345fbe31b41dc5bf4'
          '2095c6a471634cc9574b24a9b661d1f32952a11a'
          '1a207233e2746933df6334f0316fb62a0505830b'
          'b3c0c389481fece1b00257e5c8ce73256448196b'
          '39697816b3f3c37bd898ef7380af3b224b99545c')

timezones=('africa' 'antarctica' 'asia' 'australasia'
           'europe' 'northamerica' 'southamerica'
           'pacificnew' 'etcetera' 'backward'
           'systemv' 'factory')

prepare() {
  cd ${srcdir}

  patch -p1 -i ${srcdir}/tzcode-makefile.patch
  patch -p1 -i ${srcdir}/tzcode-makefile-exe-extensions.patch
  patch -p1 -i ${srcdir}/tzcode-tzfile.patch
  patch -p1 -i ${srcdir}/tzcode-cygwin.patch
  patch -p1 -i ${srcdir}/tzcode-man1.patch
  patch -p1 -i ${srcdir}/tzcode-man3.patch
  patch -p1 -i ${srcdir}/tzcode-man8.patch

}

build() {
 cd ${srcdir}

 make CFLAGS="${CFLAGS} -std=gnu99"
}

package() {
  cd ${srcdir}

  make -j1 DESTDIR=${pkgdir} install
  mv ${pkgdir}/usr/share/zoneinfo-leaps ${pkgdir}/usr/share/zoneinfo/right
  mv ${pkgdir}/usr/share/zoneinfo-posix ${pkgdir}/usr/share/zoneinfo/posix

  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo ${timezones[@]}
  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo/posix ${timezones[@]}
  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo/right -L leapseconds ${timezones[@]}

  ./zic -y ./yearistype -d ${pkgdir}/usr/share/zoneinfo -p America/New_York
  install -m444 -t ${pkgdir}/usr/share/zoneinfo iso3166.tab zone.tab
}
